class User < ActiveRecord::Base
  #attr_accessible :email, :password, :password_confirmation

  has_many :prints, :order => "created_at desc"
  has_many :payments, :order => "created_at desc"
  has_many :messages, :order => 'created_at asc'
  
  belongs_to :group

  acts_as_authentic
  
  validates_presence_of :name, :message => "nie może być pusta."
  validates_format_of :phone,
    :with => /^(([\d]{3}\s[\d]{3}\s[\d]{3})|([\d]{9})|(.?))$/,
    :message => "ma nieprawidłowy format (spróbuj XXX YYY ZZZ)",
    :allow_blank => true
  validates_numericality_of :gg_uid, :allow_blank => true, :only_integer => true  
  
  COLORS = [["błętit nieba", "#00B9F8"], ["czeluść piekieł", "#FA4444"],
      ["fiolet fioletu", '#9900CC'], ['gorący zachód słońca', '#FF9900'],
      ['świeża trawa', '#14C75D'] ]

  def deliver_password_reset_instructions!
    reset_perishable_token!
    Notifier.deliver_password_reset_instructions(self)
  end

  #<%= pluralize User.logged_in.count, "user" %> currently logged in<br /> <!-- This based on last_request_at, if they were active < 10 minutes they are logged in -->

  def deliver_activation_instructions!
    reset_perishable_token!
    Notifier.deliver_activation_instructions(self)
  end

  def deliver_print_notification!
    Notifier.deliver_print_notification(self)
  end

  def active?
    active
  end

  def activate!
    self.active = true
    save
  end

  def login!
    self.logged_in = true
    save
  end

  def logout!
    self.logged_in = false
    save
  end

  def admin?
    if self.group.name ==  "Administratorzy"
      return true
    end
  end

  def may_add?
    if self.group.may_add
      return true
    end
  end

end
